<?php
function sendSms($mobile,$data){
	$post_data = array();
	$post_data['userid'] = C("__ACCOUNT__");//iconv('GB2312', 'GB2312',"询问对接人");
	$post_data['password'] = C("__PSWD__");//iconv('GB2312', 'GB2312',"询问对接人");
	$post_data['destnumbers'] =$mobile;
	$post_data["sendtime"]="";//sendtime参数格式为 YYYY-MM-DD HH:MM:SS 如:2008-05-12 10:00:00
	$post_data['msg']=mb_convert_encoding("$data",'UTF-8', 'auto');
	$url='http://211.147.244.114:9801/CASServer/SmsAPI/SendMessage.jsp';
	//构成请求url地址
	
	$o="";
	foreach ($post_data as $k=>$v)
	{
		$o.= "$k=".urlencode($v)."&";
	}
	$post_data=substr($o,0,-1);
	//curl会话
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_URL,$url);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//设置只将数据返回，不自动输出任何数据
	$result =curl_exec($ch);
	curl_close ( $ch );
	//分解返回值
	$arr = explode(" ", $result);
	$var = array();
	for($i = 1;$i<count($arr);$i++){
		$res = explode("=", $arr[$i]);
		$var[$res[0]] = trim($res[1],"\"");
	}
	
	$sms= M("Smssubscribe");
	$sms->mobile = $mobile;
	$sms->secret = $data;
	$sms->create_time = time();
	$sms->enable = $var['return'];
	$sms->msgid = $var["msgid"];
	$sms->add();
	if(!$var['return']){
		$value = ["send" => "success"];
		header("Content-Type: text/json");
		die(json_encode($value));
	}else{
		$value = ["send" => "wrong"];
		header("Content-Type: text/json");
		die(json_encode($value));
	}
}

function getEachOrder($y,$m){
	$start = strtotime("$y-$m-1");
	$n = $m+1;
	$end = strtotime("$y-$n-1")-1;
	$count = M("Task")->where("pay_status ='pay' and create_time>$start and create_time < $end")->count();
	return $count;
}

function noLimitCity($categories,$parent_id = 0,$level = 0,$stop_id = 0){
	//定义数组保存结果
	static $lists = array();

	//遍历数组
	foreach($categories as $k => $cat){
		//先判断当前商品分类的id是否等于不需要的那个商品分类的id
		if($cat['code'] != $stop_id){
			//判断当前的商品分类是否属于要找
			if($cat['parent_id'] == $parent_id){
				//将当前层级添加到$cat数组中
				$cat['level'] = $level;

				$lists[] = $cat;

				//当前分类有可能有子分类
				//递归点
				noLimitCategory($categories,$cat['parentId'],$level + 1,$stop_id);
			}
		}
	}
	//递归出口：数组遍历结束

	//返回当前结果
	return $lists;
}